
from selenium.webdriver.common.by import By
from selenium.webdriver.support.select import Select
from page.login_page import LoginPage
from selenium import webdriver
from time import sleep
from page.page_base import BasePage
class AddredBao(BasePage):
    loc_find=(By.CSS_SELECTOR, "#menu-ul > li.collapse.lis.ico_2")
    loc_redbao = (By.XPATH, "//*[@id='menu-ul']/li[2]/ul/li[2]/a")
    loc_hongbao = (By.XPATH, "/html/body/h1/span[1]/a")
    loc_input_minchen = (By.XPATH, "/html/body/div[1]/form/table/tbody/tr[1]/td[2]/input")
    loc_input_jiner = (By.XPATH, "/html/body/div[1]/form/table/tbody/tr[2]/td[2]/input")
    loc_click_sure = (By.XPATH, "/html/body/div[1]/form/table/tbody/tr[10]/td[2]/input[1]")
    loc_input_keys = (By.XPATH, "//*[@id='keyword']")
    loc_search_btn = (By.XPATH, "/html/body/div[2]/div[2]/div/form/span[2]")
    loc_photo = (By.XPATH, "//*[@id='compareForm']/div/div/a/img")
    loc_ecs_formbuy = (By.XPATH, "//*[@id='ECS_FORMBUY']/ul[3]/li[2]/a/img")
    loc_enter_buy = (By.CSS_SELECTOR, "body > div.block.table > div.flowBox > table > tbody > tr > td:nth-child(2) > a > img")
    loc_lg_user_a = (By.XPATH, "//*[@id='username']")
    loc_lg_user_b = (By.XPATH, "//*[@id='loginForm']/table/tbody/tr[2]/td[2]/input")
    loc_lg_user_c = (By.XPATH, "//*[@id='loginForm']/table/tbody/tr[5]/td/div/input[1]")
    loc_use_redbao = (By.CSS_SELECTOR, "#ECS_BONUS")
    loc_submit = (By.CSS_SELECTOR, "#theForm > div:nth-child(14) > div:nth-child(3) > input[type=image]:nth-child(1)")

    def find(self):
    # 操作方法
        self.driver.find_element(*self.loc_find).click()
        sleep(3)
    def red_package(self):
        # 红包类型
        self.driver.find_element(*self.loc_redbao).click()
        #退出菜单的frame
        self.driver.switch_to.parent_frame()
        # 切入主界面的frame
        self.driver.switch_to.frame("main-frame")
    def add_hongbao(self):
        self.driver.find_element(*self.loc_hongbao).click()
        sleep(3)
        # 输入名称
    def input_minchen(self):
        self.driver.find_element(*self.loc_input_minchen).send_keys("红包")
        # 输入金额
    def input_jiner(self):
        self.driver.find_element(*self.loc_input_jiner).send_keys("30")
        sleep(3)
    def click_sure(self):
        # 确定添加
        self.driver.find_element(*self.loc_click_sure).click()
    #去前台验证是否添加成功并成功使用
    def get_page(self):
        self.driver.get("http://192.168.4.54:8081/upload/")
    #输入搜索内容
    def input_keys(self):
        self.driver.find_element(*self.loc_input_keys).send_keys("毛衣外套")
    #点击搜索
    def search_btn(self):
        self.driver.find_element(*self.loc_search_btn).click()
    #点击搜索的商品
    def photo(self):
        self.driver.find_element(*self.loc_photo).click()
    ##点击立即购买
    def ecs_formbuy(self):
        self.driver.find_element(*self.loc_ecs_formbuy).click()
    #点击购物中心
    def center_buy(self):
        self.driver.find_element(*self.loc_enter_buy).click()
    sleep(4)
    #登录
    def lg_user(self):
        self.driver.find_element(*self.loc_lg_user_a).send_keys("lwx")
        self.driver.find_element(*self.loc_lg_user_b).send_keys("123456")
        self.driver.find_element(*self.loc_lg_user_c).click()
    def use_redbao(self):
        self.driver.find_element(*self.loc_use_redbao).send_keys("红包[￥222.00元]")
    def submit_buy(self):
        self.driver.find_element(*self.loc_submit).click()
        sleep(5)
    #汇总
    def adredbao(self):
        self.find()
        self.red_package()
        self.add_hongbao()
        self.input_minchen()
        self.input_jiner()
        self.click_sure()
        self.get_page()
        self.input_keys()
        self.search_btn()
        self.photo()
        sleep(3)
        self.ecs_formbuy()
        sleep(3)
        self.center_buy()
        sleep(3)
        self.lg_user()
        sleep(5)
        self.use_redbao()
        sleep(5)
        self.submit_buy()
        sleep(3)